# load data
datos <- read.table("ping_dom20h_100r.out", header=T) # host ping hr fibra lping
graf <- "ping_dom20h_100r.png"

hosts  = datos$host
pings  = datos$ping
fibras = datos$fibra
lpings = datos$lping

len = length(hosts)

print(datos)

# plot
png(filename=graf, width=1024, height=768, bg="white")

par(mar=c(10,5,5,2))  # manipulate margins (bottom,left,top,right)

g_range <- range(0, pings, fibras, lpings)  # Calculate range from 0 to max value

# Graph using y-axis that g_ranges 
# Turn off axes and annotations (axis labels) so we can specify them ourself
plot(rep(1000, len), type="l", col="grey80", ylim=g_range, axes=FALSE, ann=FALSE)

# Make y-axis with horizontal labels that display ticks at 
# every 100 marks. 100*0:g_range[2] is equivalent to c(0,100,200,...,1000).
axis(2, las=1, at=100*0:g_range[2])

# Make x-axis tick marks without labels
axis(1, lab=F, at=1:len)

# Plot x-axis labels at default tick marks with labels at 45 degree angle
text(1:len, par("usr")[3] - 50, srt=45, adj=1, labels=hosts, xpd=T, cex=0.8)

box() # box around plot

lines(pings,  type="b", pch=21, lty=1, col="blue")        # plot ping
lines(fibras, type="b", pch=22, lty=1, col="red")         # plot fibras
lines(lpings, type="b", pch=20, lty=3, col="forestgreen") # plot linux ping

title(main="Mediciones de Ping a Universidades \n
            Promedio de RTT sobre 100 repeticiones - Domingo 20hs",
      xlab="", ylab="Time (ms)")      # titles

# legend: x-pos, y-pos, names, ...
legend(0.65, 1330, c("TIMEOUT","Ping","Fibra","Linux-Ping"), cex=0.8,
        col=c("grey80", "blue","red","forestgreen"),
        pch=c(45,21,22,20), lty=c(1,0,0,0))

dev.off()
